# coding:utf-8
import threading
import time

exit_flag = 0


def print_time(thread_name, counter, delay):
    while counter:
        if exit_flag:
            thread_name.exit()
        time.sleep(delay)
        print("%s:%s" % (thread_name, time.ctime(time.time())))
        counter -= 1


class myThread(threading.Thread):
    def __init__(self, thread_id, name, counter):
        threading.Thread.__init__(self)
        self.thread_id = thread_id
        self.name = name
        self.counter = counter

    def run(self):
        print("开始线程：" + self.name)
        print_time(self.name, self.counter, 5)
        print("退出线程：" + self.name)


thread_a = myThread(1, "Thread-A", 4)
thread_b = myThread(2, "Thread-B", 4)

thread_a.start()
thread_b.start()

thread_a.join()
thread_b.join()

print("退出主线程")
